<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace Lib;

/**
 * Description of Comment
 *
 * @author Boot
 */
class Comment {

    private $db;
    private $table;
    
    public function __construct( $db, $table ) {
        $this->db = $db;
        $this->table = $table;
    }
    
    public function GetComment ( $parentId ) {
        return $this->db->select( $this->table, ['comment_id', 'time', 'nick', 'comment' ] , [ 'parent_id' => $parentId, 'ORDER' => 'time DESC' ]);
    }
    
    public function AddComment ( $parentId, $commentId, $time, $nick, $comment ) {
        $this->db->insert( $this->table, [ 'parent_id' => $parentId, 'comment_id' => $commentId, 'time' => $time, 'nick' => $nick, 'comment' => $comment ]);
    }
    
    public function DelComment ( $parentId, $commentId ){
        
    }
    
    public function GetCommentNum( $parentId ) {
        return $this->db->count( $this->table, [ 'parent_id' => $parentId ] );
    }
}
